package com.xhm.bbs.help;

import com.xhm.bbs.pojo.dto.*;
import com.xhm.bbs.pojo.po.*;
import com.xhm.bbs.service.UserService;
import com.xhm.common.util.SafeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.xhm.bbs.pojo.example.UserExample.*;

@Component
public class UserHelper {

    @Autowired
    private UserService userService;

    /**
     * 生成add测试数据
     * @return
     */
    public UserAddDTO getUserAddDTO(){
        UserAddDTO dto = new UserAddDTO();
        dto.setUserName(E_USER_NAME);
        dto.setAge(SafeUtil.getInteger(E_AGE));
        dto.setOrderNo(SafeUtil.getInteger(E_ORDER_NO));
        return dto;
    }


    /**
     * 生成update测试数据
     * @return
     */
    public UserUpdateDTO getUserUpdateDTO(UserPO user){
        UserUpdateDTO dto = new UserUpdateDTO();
        dto.setId(user.getId());
        dto.setUserName(user.getUserName());
        dto.setAge(user.getAge());
        dto.setOrderNo(user.getOrderNo());
        return dto;
    }

    /**
     * 保存示例
     * @return
     */
    public UserPO saveUserExample(){
        UserAddDTO addDTO = this.getUserAddDTO();
        return userService.save(addDTO);
    }



}

